import React from 'react'
import {useSelector,useDispatch} from 'react-redux'
import {incrementAction} from '../../redux/action'

export default function Counter() {
  const count=useSelector((state)=>{
     return state.num
  })
  const dispatch=useDispatch()
  const increment=()=>{
    dispatch(incrementAction(2))
  }
  return (
    <div>
      <h1>计数器:{count}</h1>
      <button onClick={()=>{increment()}}>+</button>
    </div>
  )
}
